home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / Multi-Panel Dialogs 1.1 / MPD Sources / Generic Classes / CIncludeView.cp next >
Encoding:
Text File  |  1996-09-09  |  6.2 KB  |  168 lines  |  [TEXT/R*ch]

  1. // ===========================================================================
  2. //    File:                        CIncludeView.cp
  3. // Version:                    1.0 - Feb 1, 1996
  4. //    Author:                    Mike Shields (mshields@inconnect.com)
  5. //                            
  6. //    Copyright ©1996 Mike Shields. All rights reserved.
  7. //    I hereby grant users of CIncludeView permission to use it (or any modified 
  8. //    version of it) in applications (or any other type of Macintosh software 
  9. //    like extensions -- freeware, shareware, commercial, or other) for free, 
  10. //    subject to the terms that:
  11. //
  12. //        (1)  This agreement is non-exclusive.
  13. //
  14. //        (2)  I, Mike Shields, retain the copyright to the original source code.
  15. //
  16. //    These two items are the only required conditions for use. However, I do have 
  17. //    an additional request. Note, however, that this is only a request, and 
  18. //    that it is not a required condition for use of this code.
  19. //
  20. //        (1) That I be given credit for CIncludeView code in the copyrights or 
  21. //            acknowledgements section of your manual or other appropriate documentation.
  22. //
  23. //
  24. //    I would like to repeat that this last item is only a request. You are prefectly 
  25. //    free to choose not to do any or all of them.
  26. //    
  27. //        This source code is distributed in the hope that it will be useful,
  28. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. // ===========================================================================
  31. //    CIncludeView.h        <- double-click + Command-D to see class declaration
  32. //
  33. // Class which controls the loading and disposing of a subpane.
  34.  
  35. #include "CIncludeView.h"
  36.  
  37. #include <PP_Constants.h>
  38. #include <LStream.h>
  39. #include <UDrawingState.h>
  40. #include <UReanimator.h>
  41.  
  42. #pragma mark === Construction & Destruction ===
  43.  
  44. //----------------------------------------------------------------------------------------
  45. // CIncludeView::CreateFromStream 
  46. //----------------------------------------------------------------------------------------
  47. // Static function registered with URegistrar to create a IncludeView from the data in a stream
  48. CIncludeView* CIncludeView::CreateFromStream(LStream *inStream)
  49. {
  50.     return (new CIncludeView(inStream));
  51. }
  52.  
  53. //----------------------------------------------------------------------------------------
  54. // CIncludeView::CIncludeView 
  55. //----------------------------------------------------------------------------------------
  56. // Default constructor
  57. CIncludeView::CIncludeView()
  58.     : mCurrentIncludedPane(nil), mPaneID(PaneIDT_Undefined)
  59. {
  60. }
  61.  
  62. //----------------------------------------------------------------------------------------
  63. // CIncludeView::CIncludeView 
  64. //----------------------------------------------------------------------------------------
  65. //    Does shallow copy; SubPanes are not copied.
  66. CIncludeView::CIncludeView(const CIncludeView &inOriginal) 
  67.     : LView(inOriginal), mCurrentIncludedPane(nil)
  68. {
  69.     mPaneID = inOriginal.mPaneID;
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. // CIncludeView::CIncludeView 
  74. //----------------------------------------------------------------------------------------
  75. // create an IncludeView from the passed in data
  76. CIncludeView::CIncludeView(const SPaneInfo &inPaneInfo, const SViewInfo &inViewInfo, 
  77.                                     ResIDT inStartingPane) 
  78.     : LView(inPaneInfo, inViewInfo), mCurrentIncludedPane(nil)
  79. {
  80.     mPaneID = inStartingPane;
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // CIncludeView::CIncludeView 
  85. //----------------------------------------------------------------------------------------
  86. // create an IncludeView from the data in the stream
  87. CIncludeView::CIncludeView(LStream *inStream) 
  88.     : LView(inStream), mCurrentIncludedPane(nil)
  89. {
  90.     inStream->ReadData(&mPaneID, sizeof(ResIDT));
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. // CIncludeView::~CIncludeView 
  95. //----------------------------------------------------------------------------------------
  96. // Destructor
  97. CIncludeView::~CIncludeView()
  98. {
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // CIncludeView::FinishCreateSelf
  103. //----------------------------------------------------------------------------------------
  104. // When the creation process is compelete, we need to read in the view we've been asked to 
  105. // include initially. We do this now because everything has settled down from the creation 
  106. // process and everything else is fully constructed.
  107. void CIncludeView::FinishCreateSelf()
  108. {
  109.     if ( mPaneID != PaneIDT_Undefined )
  110.     {
  111.         LoadSubPane();
  112.     }
  113. }
  114.  
  115. #pragma mark === Subview creation/deletion ===
  116. //----------------------------------------------------------------------------------------
  117. // CIncludeView::IncludeView
  118. //----------------------------------------------------------------------------------------
  119. // This function is called when a pane is to be read in from a PPob resource and added as 
  120. // this view's subview.
  121. void CIncludeView::IncludeView(ResIDT inPaneID, Boolean inRefresh)
  122. {
  123.     if ( mCurrentIncludedPane != nil )
  124.     {
  125.         DisposeSubPane();
  126.     }
  127.     
  128.     // Prevent List and Control Managers from automatically drawing by setting
  129.     // an empty clipping region
  130.     StClipRgnState    saveClip(nil);    
  131.     
  132.     mPaneID = inPaneID;
  133.     LoadSubPane();
  134.     
  135.     if ( inRefresh )
  136.     {
  137.         Refresh();
  138.     }
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // CIncludeView::DisposeSubPane
  143. //----------------------------------------------------------------------------------------
  144. // remove the subpane from our subpane list and free it.
  145. void CIncludeView::DisposeSubPane()
  146. {
  147.     delete mCurrentIncludedPane;
  148.     
  149.     mCurrentIncludedPane = nil;
  150.     mPaneID = PaneIDT_Undefined;
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // CIncludeView::LoadSubPane
  155. //----------------------------------------------------------------------------------------
  156. // Load in a subpane from a a PPob resource, add it to our subpane list and initialize it 
  157. // as if it was being read in at window creation time
  158. void CIncludeView::LoadSubPane()
  159. {
  160.     LView    *defaultView = LPane::GetDefaultView();
  161.     
  162.     LPane::SetDefaultView(this);
  163.     mCurrentIncludedPane = (LPane*)UReanimator::ReadObjects('PPob', mPaneID);
  164.     LPane::SetDefaultView(defaultView);
  165.  
  166.     mCurrentIncludedPane->FinishCreate();
  167. }
  168.